casper.test.assert(true, "true's true");
casper.test.assert(!false, "truth is out");
casper.test.begin('assertDoesntExist() tests', 1, function(test) {
    casper.start().then(function() {
        this.setContent('<div class="heaven"></div>');
        test.assertDoesntExist('.taxes');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertEquals() tests', 3, function(test) {
    test.assertEquals(1 + 1, 2);
    test.assertEquals([1, 2, 3], [1, 2, 3]);
    test.assertEquals({a: 1, b: 2}, {a: 1, b: 2});
    test.done();
});

casper.test.begin('assertEval() tests', 1, function(test) {
    casper.start().then(function() {
        this.setContent('<div class="heaven">beer</div>');
        test.assertEval(function() {
            return __utils__.findOne('.heaven').textContent === 'beer';
        });
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertEvalEquals() tests', 1, function(test) {
    casper.start().then(function() {
        this.setContent('<div class="heaven">beer</div>');
        test.assertEvalEquals(function() {
            return __utils__.findOne('.heaven').textContent;
        }, 'beer');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertElementCount() tests', 3, function(test) {
    casper.start().then(function() {
        this.page.content = '<ul><li>1</li><li>2</li><li>3</li></ul>';
        test.assertElementCount('ul', 1);
        test.assertElementCount('li', 3);
        test.assertElementCount('address', 0);
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertExists() tests', 1, function(test) {
    casper.start().then(function() {
        this.setContent('<div class="heaven">beer</div>');
        test.assertExists('.heaven');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertField() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        this.fill('form[name="f"]', { q: 'plop' }, false);
        test.assertField('q', 'plop');
    }).run(function() {
        test.done();
    });
});

// // Path usage with type 'css'
casper.test.begin('assertField() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        this.fill('form[name="f"]', { q: 'plop' }, false);
        test.assertField({type: 'css', path: 'input#lst-ib'}, 'plop');
    }).run(function() {
        test.done();
    });
}); 

casper.test.begin('assertFieldName() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        this.fill('form[name="f"]', { q: 'plop' }, false);
        test.assertFieldName('q', 'plop', 'did not plop', {formSelector: 'plopper'});
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertFieldCSS() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        this.fill('form[name="f"]', { q: 'plop' }, false);
        test.assertFieldCSS('q', 'plop', 'did not plop', 'input.plop');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertFieldXPath() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        this.fill('form[name="f"]', { q: 'plop' }, false);
        test.assertFieldXPath('q', 'plop', 'did not plop', '/html/body/form[0]/input[1]');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('casperjs.org is up and running', 1, function(test) {
    casper.start('http://casperjs.org/', function() {
        test.assertHttpStatus(200);
    }).run(function() {
        test.done();
    });
});

casper.test.assertMatch('Chuck Norris', /^chuck/i, 'Chuck Norris\' first name is Chuck');

casper.test.assertNot(false, "Universe is still operational");


casper.test.begin('assertNotVisible() tests', 1, function(test) {
    casper.start().then(function() {
        this.setContent('<div class="foo" style="display:none">boo</div>');
        test.assertNotVisible('.foo');
    }).run(function() {
        test.done();
    });
});

casper.test.assertRaises(function(throwIt) {
    if (throwIt) {
        throw new Error('thrown');
    }
}, [true], 'Error has been raised.');

casper.test.assertRaises(function(throwIt) {
    if (throwIt) {
        throw new Error('thrown');
    }
}, [false], 'Error has been raised.'); // fails


casper.test.begin('assertSelectorDoesntHaveText() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertSelectorDoesntHaveText('title', 'Yahoo!');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertSelectorHasText() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertSelectorHasText('title', 'Google');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertResourceExists() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertResourceExists(function(resource) {
            return resource.url.match('logo3w.png');
        });
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertTextExists() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertTextExists('google', 'page body contains "google"');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertTextDoesntExist() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertTextDoesntExist('bing', 'page body does not contain "bing"');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertTitle() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertTitle('Google', 'google.com has the correct title');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertTitleMatch() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertTitleMatch(/Google/, 'google.com has a quite predictable title');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertType() tests', 1, function suite(test) {
    test.assertType(42, "number", "Okay, 42 is a number");
    test.assertType([1, 2, 3], "array", "We can test for arrays too!");
    test.done();
});

function Cow() {
    this.moo = function moo() {
        return 'moo!';
    };
}
casper.test.begin('assertInstanceOf() tests', 2, function suite(test) {
    var daisy = new Cow();
    test.assertInstanceOf(daisy, Cow, "Ok, daisy is a cow.");
    test.assertInstanceOf(["moo", "boo"], Array, "We can test for arrays too!");
    test.done();
});

casper.test.begin('assertUrlMatch() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertUrlMatch(/^http:\/\//, 'google.com is served in http://');
    }).run(function() {
        test.done();
    });
})

casper.test.begin('assertVisible() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertVisible('h1');
    }).run(function() {
        test.done();
    });
});

casper.test.begin('assertAllVisible() tests', 1, function(test) {
    casper.start('https://www.google.com/?gws_rd=cr,ssl', function() {
        test.assertAllVisible('input[type="submit"]');
    }).run(function() {
        test.done();
    });
});

